package com.example.demo.leetcode.classics150;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _9跳跃游戏
 * @description
 * @date 2023/07/10 10:11
 * <p>
 * ******************************************************
 */
public class _9跳跃游戏 {

    public boolean canJump(int[] nums) {
        int length = nums.length;

        boolean[] dp = new boolean[length];
        dp[0] = true;

        for (int i = 0; i < length; i++) {
            if (dp[i]) {
                for (int j = 1; j <= nums[i] && i + j < length; j++) {
                    dp[i + j] = true;
                }
            }
            if (dp[length - 1]) {
                return true;
            }
        }

        return false;
    }
}
